package com.work.storage.repository;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.work.storage.entity.Storage;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

/**
 * Program Name: springcloud-nacos-seata
 * <p>
 * Description:
 * <p>
 *
 * @author zhangjianwei
 * @version 1.0
 * @date 2019/8/28 4:05 PM
 */
@Mapper
@Repository
public interface StorageDAO extends BaseMapper<Storage> {

    @Select("select * from storage_tbl where id = #{id}")
    Storage selectByStorageIdNotLock(@Param(value = "id") Integer id);


    @Select("select * from storage_tbl where id = #{id} for update")
    Storage selectByStorageId(@Param(value = "id") Integer id);

    @Update("update storage_tbl set version = #{version} + 1, count = #{count} where id = #{id} and version = #{version}")
    Integer updateByStorageIdAndVersion(@Param(value = "id") Long id, @Param(value = "count") Long count, @Param(value = "version") Long version);

}
